import time
from selenium import webdriver
from selenium.webdriver.common.by import By
import unittest

class kugou(unittest.TestCase):

    def setUp(self) -> None:
        # 打开浏览器
        self.driver = webdriver.Chrome()
        self.driver.get('https://www.kugou.com/')
        time.sleep(2)
        # 窗口最大化
        self.driver.maximize_window()
        time.sleep(2)
        self.driver.implicitly_wait(5)

    def tearDown(self) -> None:
        time.sleep(5)
        # self.driver.quit()

    def test_kugou_01(self):
        # 点击登录
        self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div[2]/div[1]').click()
        time.sleep(3)
        # 进入frame框架
        f = self.driver.find_element(By.XPATH, '//*[@id="loginIframe"]')
        self.driver.switch_to.frame(f)
        time.sleep(3)
        # 点击手机号登录
        self.driver.find_element(By.ID, 'j_kg_popup_switch').click()
        time.sleep(3)
        # 输入手机号
        self.driver.find_element(By.ID, 'KgPopupPhone').send_keys('15985645480')
        # 强制等待，输入验证码
        time.sleep(30)
        # 点击登录
        self.driver.find_element(By.CLASS_NAME, 'kg_popup_login_btn').click()
        time.sleep(2)
        # 断言1：验证登录成功后断言：小高先生
        dy1 = self.driver.find_element(By.CLASS_NAME, 'cmhead1_sp1').text
        self.assertEqual('小高先生', dy1)



if __name__ == '__main__':
    unittest.main()




